var e = require;
var t = module;
var o = exports;
Object.defineProperty(o, "__esModule", {value: !0});
var n = e("BaseModuleUI"),
    a = e("NotifyEventType"),
    i = e("GlobalParams"),
    r = e("AssetsManager"),
    s = e("AudioManager"),
    l = e("EquipInfo"),
    c = e("RoleSoldierInfo"),
    d = e("UIManager"),
    h = e("sdkConfig"),
    _ = e("AD"),
    u = e("BuyEquipInfo"),
    p = cc._decorator,
    m = p.ccclass,
    f = p.property,
    g = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.skill_one_btn = null),
                (t.skill_two_btn = null),
                (t.one_add_skill_node = null),
                (t.two_add_skill_node = null),
                (t.skill_one_cooling_label = null),
                (t.skill_two_cooling_label = null),
                (t.team_kill_left = null),
                (t.team_kill_right = null),
                (t.kill_num_label = null),
                (t.die_num_label = null),
                (t.assist_num_label = null),
                (t.player_skill_one_image = null),
                (t.player_skill_two_image = null),
                (t.player_skill_one_name = null),
                (t.player_skill_two_name = null),
                (t.top_node_item = null),
                (t.coin_num_label = null),
                (t.equip_item = null),
                (t.buy_equip_item = null),
                (t.myNomEquipInfo = []),
                (t.show_equip_info = null),
                t
            );
        }
        return (
            __extends(t, e),
            (t.prototype.initView = function () {
                this.buy_equip_item.setPosition(cc.v2(-520, 110)),
                    (this.buy_equip_item.active = !1),
                    (i.GlobalParams.GameTeamKillInfo = [0, 0]),
                    (this.team_kill_left.string = "" + i.GlobalParams.GameTeamKillInfo[0]),
                    (this.team_kill_right.string = "" + i.GlobalParams.GameTeamKillInfo[1]),
                    this.showMyKillInfo(),
                    this.showAddSkillNode(),
                    this.showHeroSkillInfo(),
                    this.updatePlayerCoin();
                var e = i.GlobalParams.MatchGamePlayer[i.GlobalParams.MatchMyIndex].player_skill;
                (this.player_skill_one_image.spriteFrame = r.default
                    .getInstance()
                    .getPlayerSkillFrame("skill_" + e[0])),
                    (this.player_skill_one_name.string = c.default.Player_Skill_Info[e[0] - 1].name),
                    (this.player_skill_two_image.spriteFrame = r.default
                        .getInstance()
                        .getPlayerSkillFrame("skill_" + e[1])),
                    (this.player_skill_two_name.string = c.default.Player_Skill_Info[e[1] - 1].name),
                    (this.myNomEquipInfo =
                        l.default.equip_nominate_info[
                            i.GlobalParams.MatchGamePlayer[i.GlobalParams.MatchMyIndex].role_id
                        ].nom_equip);
            }),
            (t.prototype.addEvent = function () {
                this.attachEvent(a.default.SEND_PLAYER_SKILL_COOLING_TIME, this.showCoolingTime, this),
                    this.attachEvent(a.default.SEND_PLAYER_LEVEL_UP_INFO, this.playerLevelUp, this),
                    this.attachEvent(a.default.SEND_ROLE_BE_KILL_INFO, this.showTeamKillInfo, this),
                    this.attachEvent(a.default.SEND_UPDATE_MATCH_PLAYER_INFO, this.updatePlayerCoin, this),
                    this.attachEvent(a.default.SEND_UPDATE_PLAYER_REVIVE_INFO, this.showHeroSkillInfo, this);
            }),
            (t.prototype.OnClick = function (t) {
                var o = this;
                e.prototype.OnClick.call(this, t);
                var n = t.node,
                    p = n.name;
                switch (p) {
                    case "add_skill_one":
                    case "add_skill_two":
                        i.GlobalParams.MatchGamePlayer[i.GlobalParams.MatchMyIndex].skill_info[
                            "add_skill_one" == p ? 0 : 1
                        ]++;
                        var m = i.GlobalParams.MatchGamePlayer[i.GlobalParams.MatchMyIndex];
                        "add_skill_one" == p
                            ? (i.GlobalParams.GamePlayerInfo[i.GlobalParams.MatchMyIndex].skill_1 +=
                                  c.default.Role_info[m.role_id].S1_attack_up)
                            : "add_skill_two" == p &&
                              (i.GlobalParams.GamePlayerInfo[i.GlobalParams.MatchMyIndex].skill_2 +=
                                  c.default.Role_info[m.role_id].S2_attack_up),
                            this.showAddSkillNode();
                        break;
                    case "player_skill_one":
                    case "player_skill_two":
                        var f = n.getChildByName("cooling");
                        if (f.active) return;
                        var g =
                            i.GlobalParams.MatchGamePlayer[i.GlobalParams.MatchMyIndex].player_skill[
                                "player_skill_one" == p ? 0 : 1
                            ];
                        this.emitEvent(a.default.SEND_PLAYER_USE_PLAYER_SKILL, g), (f.active = !0);
                        var v = c.default.Player_Skill_Info[g - 1].cooling;
                        2 == i.GlobalParams.ChangeGameMode && (v /= 2), this.playerSkillCooling(f, v, v);
                        break;
                    case "menu_btn":
                    case "kill_info_node":
                        h.default.platform == h.EPlatform.TikTok && _.default.getInstance().PauseRecorder(),
                            cc
                                .find("Canvas")
                                .addChild(cc.instantiate(r.default.getInstance().getFightPrefab("GameMenuViewUI")));
                        break;
                    case "go_fight_btn":
                        this.showTopInfoNode(0), s.default.getInstance().playFx("go_fight");
                        break;
                    case "gather_btn":
                        this.showTopInfoNode(1), s.default.getInstance().playFx("gather");
                        break;
                    case "retreat_btn":
                        this.showTopInfoNode(2), s.default.getInstance().playFx("retreat");
                        break;
                    case "praise_btn":
                        this.showTopInfoNode(3), s.default.getInstance().playFx("good_job");
                        break;
                    case "setting_btn":
                        h.default.platform == h.EPlatform.TikTok && _.default.getInstance().PauseRecorder(),
                            cc.find("UIManager").getComponent(d.default).showPopup("SettingViewUI");
                        break;
                    case "coin_node":
                        h.default.platform == h.EPlatform.TikTok && _.default.getInstance().PauseRecorder(),
                            cc
                                .find("Canvas")
                                .addChild(cc.instantiate(r.default.getInstance().getFightPrefab("GameEquipViewUI")));
                        break;
                    case "equip_item":
                        for (
                            var y = this.show_equip_info.eq_sale,
                                S = i.GlobalParams.MatchGamePlayer[i.GlobalParams.MatchMyIndex].equip_info,
                                I = [],
                                w = 0;
                            w < this.show_equip_info.eq_need.length;
                            w++
                        )
                            -1 != S.indexOf(this.show_equip_info.eq_need[w]) &&
                                ((y -= l.default.eqquip_info[this.show_equip_info.eq_need[w]].eq_sale),
                                I.push(S.indexOf(this.show_equip_info.eq_need[w])));
                        for (w = 0; w < I.length; w++) S[I[w]] = 0;
                        for (
                            S[S.indexOf(0)] = this.show_equip_info.eq_ID,
                                i.GlobalParams.MatchGamePlayer[i.GlobalParams.MatchMyIndex].coin -= y,
                                i.GlobalParams.MatchGamePlayer[i.GlobalParams.MatchMyIndex].equip_info = S,
                                u.default.playerBuyEquipInfo(i.GlobalParams.MatchMyIndex, function () {
                                    o.emitEvent(
                                        a.default.SEND_UPDATE_BUY_EQUIP_NEW_ADD_INFO,
                                        i.GlobalParams.MatchMyIndex
                                    );
                                }),
                                w = 0;
                            w < this.show_equip_info.eq_need.length;
                            w++
                        ) {
                            var N = i.GlobalParams.MyNomEquipInfo.indexOf(this.show_equip_info.eq_need[w]);
                            -1 != N && i.GlobalParams.MyNomEquipInfo.splice(N, 1);
                        }
                        i.GlobalParams.MyNomEquipInfo.splice(
                            i.GlobalParams.MyNomEquipInfo.indexOf(this.show_equip_info.eq_ID),
                            1
                        ),
                            this.emitEvent(a.default.SEND_UPDATE_MATCH_PLAYER_INFO),
                            (this.buy_equip_item.active = !0),
                            this.buy_equip_item.stopAllActions(),
                            this.buy_equip_item.getComponent(cc.ParticleSystem).resetSystem(),
                            cc
                                .tween(this.buy_equip_item)
                                .to(1, {position: cc.v3(0, -100, 0)})
                                .call(function () {
                                    (o.buy_equip_item.active = !1), o.buy_equip_item.setPosition(cc.v2(-520, 110));
                                })
                                .start();
                }
            }),
            (t.prototype.showTopInfoNode = function (e) {
                var t = this;
                this.unscheduleAllCallbacks();
                for (var o = 0; o < 4; o++) this.top_node_item.children[0].children[o].active = o == e;
                (this.top_node_item.children[1].getChildByName("head").getComponent(cc.Sprite).spriteFrame = r.default
                    .getInstance()
                    .getGameHoreHeadFrame(
                        c.default.Role_info[i.GlobalParams.MatchGamePlayer[i.GlobalParams.MatchMyIndex].role_id].C_ID
                    )),
                    (this.top_node_item.children[1].children[0].active = i.GlobalParams.MatchMyIndex % 2 == 0),
                    (this.top_node_item.children[1].children[0].active = i.GlobalParams.MatchMyIndex % 2 != 0),
                    (this.top_node_item.active = !0),
                    this.scheduleOnce(function () {
                        t.top_node_item.active = !1;
                    }, 1);
            }),
            (t.prototype.showCoolingTime = function (e, t) {
                var o = Number(t.time.toFixed(1));
                1 == t.type
                    ? ((this.skill_one_cooling_label.node.parent.active = !0),
                      (this.skill_one_btn.getChildByName("use_skill").active = !1),
                      this.btnCoolingInfo(this.skill_one_cooling_label, o, o))
                    : 2 == t.type &&
                      ((this.skill_two_cooling_label.node.parent.active = !0),
                      (this.skill_two_btn.getChildByName("use_skill").active = !1),
                      this.btnCoolingInfo(this.skill_two_cooling_label, o, o));
            }),
            (t.prototype.btnCoolingInfo = function (e, t, o) {
                var n = this,
                    a = e.node.parent.getChildByName("bg").getComponent(cc.Sprite);
                t <= 0
                    ? ((a.fillRange = 1), (e.node.parent.active = !1))
                    : ((t = Number(t.toFixed(1))),
                      (e.string = "" + t),
                      cc
                          .tween(a)
                          .to(1, {fillRange: t / o})
                          .call(function () {
                              t--, n.btnCoolingInfo(e, t, o);
                          })
                          .start());
            }),
            (t.prototype.playerLevelUp = function (e, t) {
                t == i.GlobalParams.MatchMyIndex && this.showAddSkillNode();
            }),
            (t.prototype.showAddSkillNode = function () {
                var e = i.GlobalParams.MatchGamePlayer[i.GlobalParams.MatchMyIndex],
                    t = e.skill_info[0] + e.skill_info[1];
                (this.one_add_skill_node.active = e.level > t && e.skill_info[0] < 5),
                    (this.two_add_skill_node.active = e.level > t && e.skill_info[1] < 5),
                    (this.skill_one_btn.getChildByName("not_learn_bg").active = 0 == e.skill_info[0]),
                    (this.skill_two_btn.getChildByName("not_learn_bg").active = 0 == e.skill_info[1]),
                    (this.skill_one_btn.getComponent(cc.Button).interactable = 0 != e.skill_info[0]),
                    (this.skill_two_btn.getComponent(cc.Button).interactable = 0 != e.skill_info[1]),
                    (this.skill_one_btn.getChildByName("level_bg").getComponent(cc.Sprite).fillRange =
                        -0.2 * e.skill_info[0]),
                    (this.skill_two_btn.getChildByName("level_bg").getComponent(cc.Sprite).fillRange =
                        -0.2 * e.skill_info[1]);
            }),
            (t.prototype.showTeamKillInfo = function (e, t) {
                var o = t;
                o.kill < 7 &&
                    o.be_kill < 7 &&
                    (o.kill % 2 == 0 ? i.GlobalParams.GameTeamKillInfo[0]++ : i.GlobalParams.GameTeamKillInfo[1]++,
                    (this.team_kill_left.string = "" + i.GlobalParams.GameTeamKillInfo[0]),
                    (this.team_kill_right.string = "" + i.GlobalParams.GameTeamKillInfo[1]),
                    this.showMyKillInfo());
            }),
            (t.prototype.showMyKillInfo = function () {
                var e = i.GlobalParams.MatchGamePlayer[i.GlobalParams.MatchMyIndex];
                (this.kill_num_label.string = "" + e.kill_info[0]),
                    (this.die_num_label.string = "" + e.kill_info[1]),
                    (this.assist_num_label.string = "" + e.kill_info[2]);
            }),
            (t.prototype.playerSkillCooling = function (e, t, o) {
                var n = this;
                if (t <= 0) e.active = !1;
                else {
                    e.getChildByName("cooling_num").getComponent(cc.Label).string = "" + t;
                    var a = e.getChildByName("bg").getComponent(cc.Sprite);
                    cc.tween(a)
                        .to(1, {fillRange: t / o})
                        .call(function () {
                            t--, n.playerSkillCooling(e, t, o);
                        })
                        .start();
                }
            }),
            (t.prototype.showHeroSkillInfo = function () {
                var e = i.GlobalParams.MatchGamePlayer[i.GlobalParams.MatchMyIndex];
                (this.skill_one_btn.getChildByName("skill_icon").getComponent(cc.Sprite).spriteFrame = r.default
                    .getInstance()
                    .getHeroSkilIcon(c.default.Role_info[e.role_id].C_ID + "01")),
                    (this.skill_two_btn.getChildByName("skill_icon").getComponent(cc.Sprite).spriteFrame = r.default
                        .getInstance()
                        .getHeroSkilIcon(c.default.Role_info[e.role_id].C_ID + "02")),
                    (this.skill_one_btn.getChildByName("skill_des").getComponent(cc.Label).string =
                        c.default.Role_info[e.role_id].S1_des),
                    (this.skill_two_btn.getChildByName("skill_des").getComponent(cc.Label).string =
                        c.default.Role_info[e.role_id].S2_des);
            }),
            (t.prototype.updatePlayerCoin = function () {
                var e = i.GlobalParams.MatchGamePlayer[i.GlobalParams.MatchMyIndex].coin;
                if (((this.coin_num_label.string = "" + e), 0 != i.GlobalParams.MyNomEquipInfo.length)) {
                    var t = i.GlobalParams.MyNomEquipInfo[0],
                        o = l.default.eqquip_info[t],
                        n = i.GlobalParams.MatchGamePlayer[i.GlobalParams.MatchMyIndex].equip_info,
                        a = 0;
                    if (o.eq_level > 1)
                        for (var s = 0; s < o.eq_need.length; s++)
                            -1 != n.indexOf(o.eq_need[s]) && (a += l.default.eqquip_info[o.eq_need[s]].eq_sale);
                    e >= o.eq_sale - a
                        ? (-1 == this.myNomEquipInfo.indexOf(t) &&
                              ((t = i.GlobalParams.MyNomEquipInfo[1]),
                              e >= l.default.eqquip_info[t].eq_sale - a &&
                                  (-1 == this.myNomEquipInfo.indexOf(t)
                                      ? ((t = i.GlobalParams.MyNomEquipInfo[2]),
                                        (o =
                                            e >= l.default.eqquip_info[t].eq_sale - a
                                                ? l.default.eqquip_info[t]
                                                : l.default.eqquip_info[i.GlobalParams.MyNomEquipInfo[1]]))
                                      : (o = l.default.eqquip_info[t]))),
                          (this.show_equip_info = o),
                          (this.equip_item.children[0].getComponent(cc.Sprite).spriteFrame = r.default
                              .getInstance()
                              .getEquipIconFrame("equip_" + o.eq_ID)),
                          (this.equip_item.children[1].getComponent(cc.Label).string = "" + o.eq_name),
                          (this.equip_item.children[3].getComponent(cc.Label).string = "" + (o.eq_sale - a)),
                          (this.equip_item.active = !0))
                        : (this.equip_item.active = !1);
                } else this.equip_item.active = !1;
            }),
            __decorate([f(cc.Node)], t.prototype, "skill_one_btn", void 0),
            __decorate([f(cc.Node)], t.prototype, "skill_two_btn", void 0),
            __decorate([f(cc.Node)], t.prototype, "one_add_skill_node", void 0),
            __decorate([f(cc.Node)], t.prototype, "two_add_skill_node", void 0),
            __decorate([f(cc.Label)], t.prototype, "skill_one_cooling_label", void 0),
            __decorate([f(cc.Label)], t.prototype, "skill_two_cooling_label", void 0),
            __decorate([f(cc.Label)], t.prototype, "team_kill_left", void 0),
            __decorate([f(cc.Label)], t.prototype, "team_kill_right", void 0),
            __decorate([f(cc.Label)], t.prototype, "kill_num_label", void 0),
            __decorate([f(cc.Label)], t.prototype, "die_num_label", void 0),
            __decorate([f(cc.Label)], t.prototype, "assist_num_label", void 0),
            __decorate([f(cc.Sprite)], t.prototype, "player_skill_one_image", void 0),
            __decorate([f(cc.Sprite)], t.prototype, "player_skill_two_image", void 0),
            __decorate([f(cc.Label)], t.prototype, "player_skill_one_name", void 0),
            __decorate([f(cc.Label)], t.prototype, "player_skill_two_name", void 0),
            __decorate([f(cc.Node)], t.prototype, "top_node_item", void 0),
            __decorate([f(cc.Label)], t.prototype, "coin_num_label", void 0),
            __decorate([f(cc.Node)], t.prototype, "equip_item", void 0),
            __decorate([f(cc.Node)], t.prototype, "buy_equip_item", void 0),
            __decorate([m], t)
        );
    })(n.default);
o.default = g;
